// pages/searchOrderDetails/searchOrderDetails.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tencent_status: 0,
    details: {},
    pay_type: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getInfo();
    this.setData({
      id: options.id
    })
    this.getData();
  },

  getData() {
    var that = this;
    var data = {
      point_url: app.server.agentApi.getTencentCloudOrderList,
      page_no: 1,
      page_size: 10,
      deal_names: this.data.id
    };
    app.server.getConnect(data).then(function(res) {
      that.setData({
        details: res.data.list[0]
      })
    })
  },

  getInfo: function () {
    var that = this;
    var data = {
      point_url: app.server.agentApi.getMemberDetail,
    };
    app.server.getConnect(data).then(function (res) {
      app.globalData.userInfo = res.data
      that.setData({
        tencent_status: res.data.tencent_status || 0
      })
    }, function (res) {
      console.log(res);
      app.showConfirm('提示', res.data.msg, false);
    })
  },

  choosePayWay: function() {
    var that = this;
    if (this.data.tencent_status===1){
      // app.showConfirm('付款方式', '', true, function () {
      //   that.setData({
      //     pay_type: 0
      //   })
      //   that.doPay();
      // }, function () {
      //   that.setData({
      //     pay_type: 1
      //   })
      //   that.doPay();
      // }, '余额', '赠送金')
      that.doPay();
    } else {
      app.showConfirm('提示', '无腾讯云代付权限,请联系管理员!',false)
    }
  },

  doPay: function() {
    var data = {
      point_url: app.server.agentApi.payTencentCloudOrder,
      title: this.data.details['goodsName'],
      amount: this.data.details['goodsNum'],
      owner_uin: this.data.details['ownerUin'],
      deal_name: this.data.details['dealName']
    };
    wx.showLoading({
      title: '支付中...',
      mask: true
    })
    app.server.getConnect(data).then(function(res) {
      wx.hideLoading();
      wx.showToast({
        title: '支付成功',
      })
      setTimeout(function() {
        wx.navigateBack();
      }, 800);
    }, function(res) {
      wx.hideLoading();
      app.showConfirm('提示', res.data.msg, false);
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    app.pageOnloadInit(this, app);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    app.pageOnloadInit(this, app);
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})
